﻿using BLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Com.Qkds.Erp.WebUi
{
    public partial class salesType : System.Web.UI.Page
    {
        public int PageIndex
        {
            get
            {
                return int.Parse(ViewState["pageIndex"].ToString());
            }
            set
            {
                ViewState["pageIndex"] = value;
            }
        }

        /// <summary>
        /// 总页数
        /// </summary>
        public int PageCount
        {
            get
            {
                return int.Parse(ViewState["PageCount"].ToString());
            }
            set
            {
                ViewState["PageCount"] = value;
            }
        }
        public int pid
        {
            get
            {
                return int.Parse(ViewState["pid"].ToString());
            }
            set
            {
                ViewState["pid"] = value;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                pid = 0;
                if (Request["id"] != null)
                {
                    pid = int.Parse(Request["id"].ToString());
                }
                // this.rpProducts.DataSource = new ProductBLL().GetModels();
                int rowsCount = new SalesTypeBLL().Lj("SalesType", "Shop").Rows.Count; //行数
                PageCount = (rowsCount / 5);
                if (rowsCount % 5 != 0)
                {
                    PageCount++;
                }
                PageIndex = 1;
                this.rpSalesType.DataSource = new SalesTypeBLL().LJA("SalesType", "Shop", pid);
                this.rpSalesType.DataBind();
            }
        }
        public void GoPage()
        {
            string TableOne = "SalesType";
            string tableTow = "shop";
            this.rpSalesType.DataSource = new SalesTypeBLL().S(TableOne, tableTow, PageIndex);
            this.rpSalesType.DataBind();
        }
        protected void sel_Click(object sender, EventArgs e)
        {
            string TableName = "SalesType";
            int id = int.Parse(this.sev.Value);
            this.rpSalesType.DataSource = new SalesTypeBLL().DSelectID(TableName, id);
            this.rpSalesType.DataBind();
        }


        protected void btnPageFirst_Click(object sender, EventArgs e)
        {

            PageIndex = 1;
            GoPage();
        }

        protected void btnPagePre_Click(object sender, EventArgs e)
        {
            if (PageIndex > 1)
            {
                PageIndex--;

            }

            GoPage();
        }

        protected void btnPageNext_Click(object sender, EventArgs e)
        {
            if (PageIndex < PageCount)
            {
                PageIndex++;
            }
            GoPage();
        }

        protected void btnPageLast_Click(object sender, EventArgs e)
        {
            PageIndex = PageCount;
            GoPage();
        }

        protected void rpSalesType_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "del")
            {
                string TableName = "SalesType";
                int id = int.Parse(e.CommandArgument.ToString());
                if (new SalesTypeBLL().Del(TableName, id))
                {
                    GoPage();
                }

            }
        }
    }
}